package com.lysj.bhp.supernode.service;

import com.lysj.bhp.supernode.base.SuperNodeContent;
import com.lysj.bhp.supernode.domain.SuperNode;
import com.lysj.bhp.supernode.domain.SuperNodeUser;
import com.lysj.bhp.util.web.ParamUtil;
import com.lysj.bhp.util.web.Resp;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class SuperNodeService extends SuperNodeContent {

    public Resp remove(SuperNode model) {
        if (ParamUtil.isBlack(model.getSuperNodeId())) {
            return new Resp(Resp.PARAM_ERROR, "请选择超级节点");
        }
        SuperNode superNode = superNodeRepository.findOne(model.getSuperNodeId());
        if (null == superNode) {
            return new Resp(Resp.PARAM_ERROR, "超级节点错误!");
        }
        superNodeRepository.delete(model.getSuperNodeId());
        //删除超级节点下的所有用户
        List<SuperNodeUser> superNodeUserList = superNodeUserRepository.findBySuperNodeId(model.getSuperNodeId());
        superNodeUserRepository.delete(superNodeUserList);
        return new Resp("删除成功");
    }

}
